//链表的回文结构
public class PalindromeList {
    public boolean chkPalindrome(ListNode head) {
        // write code here
        if(head == null || head.next == null){
            return true;
        }
        ListNode fast = head;
        ListNode slow = head;

        //1.找到中间位置
        while(fast != null && fast.next != null){
            fast = fast.next.next;
            slow = slow.next;
        }
        //2.翻转
        ListNode cur = slow.next;
        while(cur != null){
            ListNode curNext = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curNext;
        }
        //3.从前到后，从后到前
        while(head!= slow){
            if(head.val != slow.val){
                return false;
            }
            if(head.next == slow){
                return true;
            }
            head = head.next;
            slow = slow.next;
        }
        return true;

    }
}